﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SeCompUFSCarWeb.Administration
{
    public partial class Presenca : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Confirmar_Click(object sender, EventArgs e)
        {
            string strconn = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString;
            MySqlConnection conn = new MySqlConnection(strconn);

            string[] inscricoes = TextBoxInscricao.Text.Split(new string[] {Environment.NewLine}, StringSplitOptions.RemoveEmptyEntries);
            string query = "INSERT INTO secomp.presenca (INS_ID, EVE_ID) VALUES (@inscricao, @evento)";

            MySqlCommand cmd = new MySqlCommand(query, conn);
            
            conn.Open();

            foreach (string inscricao in inscricoes)
            {
                cmd.Parameters.Clear();
                cmd.Parameters.AddWithValue("@evento", Convert.ToInt32(DropBoxEvento.SelectedValue));
                cmd.Parameters.AddWithValue("@inscricao", Convert.ToInt32(inscricao));
                cmd.ExecuteNonQuery();
            }

            conn.Close();
        }
    }
}